/// <reference path="./global.d.ts" />
require(['vue', 'msg', 'storage'], function (vue, msg, storage) {
    /**
     * 地图坐标点角色
     */
    var Role;
    (function (Role) {
        /**
         * 空白
         */
        Role[Role["Blank"] = 0] = "Blank";
        /**
         * 墙
         */
        Role[Role["Wall"] = 1] = "Wall";
        /**
         * 小人
         */
        Role[Role["People"] = 2] = "People";
        /**
         * 小人点
         */
        Role[Role["PeopleDot"] = 3] = "PeopleDot";
        /**
         * 箱子
         */
        Role[Role["Chest"] = 4] = "Chest";
        /**
         * 箱子点
         */
        Role[Role["Dot"] = 5] = "Dot";
        /**
         * 到点箱子
         */
        Role[Role["ChestDot"] = 6] = "ChestDot";
    })(Role || (Role = {}));
    /**
     * 移动位置
     */
    var MovePotion;
    (function (MovePotion) {
        MovePotion[MovePotion["Up"] = 0] = "Up";
        MovePotion[MovePotion["Down"] = 1] = "Down";
        MovePotion[MovePotion["Left"] = 2] = "Left";
        MovePotion[MovePotion["Right"] = 3] = "Right";
    })(MovePotion || (MovePotion = {}));
    var People = /** @class */ (function () {
        function People(coord) {
            this.currentCoord = coord;
        }
        People.prototype.getNewCoord = function (oldCoord, potion) {
            var newCoord = {
                Y: oldCoord.Y,
                X: oldCoord.X
            };
            switch (potion) {
                case MovePotion.Up:
                    newCoord.Y--;
                    break;
                case MovePotion.Right:
                    newCoord.X++;
                    break;
                case MovePotion.Down:
                    newCoord.Y++;
                    break;
                case MovePotion.Left:
                    newCoord.X--;
                    break;
            }
            return newCoord;
        };
        People.prototype.setCoord = function (coord) {
            this.currentCoord.Y = coord.Y;
            this.currentCoord.X = coord.X;
        };
        People.prototype.move = function (potion) {
            var _this = this;
            var peopleNewCoord = this.getNewCoord(this.currentCoord, potion);
            var currentCoordRole = game.getCoordRole(this.currentCoord);
            var newCoordRole = game.getCoordRole(peopleNewCoord);
            if (!(newCoordRole == Role.Blank || newCoordRole == Role.Chest || newCoordRole == Role.Dot || newCoordRole == Role.ChestDot))
                return;
            var updateCurrentCoord = function () {
                _this.currentCoord.Y = peopleNewCoord.Y;
                _this.currentCoord.X = peopleNewCoord.X;
                game.addPace();
            };
            if (newCoordRole == Role.Blank) {
                game.setCoordRole(peopleNewCoord, Role.People);
                game.setCoordRole(this.currentCoord, currentCoordRole == Role.PeopleDot ? Role.Dot : Role.Blank);
                updateCurrentCoord();
            }
            else if (newCoordRole == Role.Dot) {
                game.setCoordRole(peopleNewCoord, Role.PeopleDot);
                game.setCoordRole(this.currentCoord, currentCoordRole == Role.PeopleDot ? Role.Dot : Role.Blank);
                updateCurrentCoord();
            }
            else if (newCoordRole == Role.Chest || newCoordRole == Role.ChestDot) {
                var newChestCoord = this.getNewCoord(peopleNewCoord, potion);
                var newChestCoordRole = game.getCoordRole(newChestCoord);
                if (newChestCoordRole == Role.Wall || newChestCoordRole == Role.ChestDot || newChestCoordRole == Role.Chest)
                    return;
                game.setCoordRole(newChestCoord, newChestCoordRole == Role.Dot ? Role.ChestDot : Role.Chest);
                game.setCoordRole(peopleNewCoord, newCoordRole == Role.ChestDot ? Role.PeopleDot : Role.People);
                game.setCoordRole(this.currentCoord, currentCoordRole == Role.PeopleDot ? Role.Dot : Role.Blank);
                updateCurrentCoord();
            }
            game.verifySuccess();
        };
        return People;
    }());
    var Map = /** @class */ (function () {
        function Map() {
            this.level = 0;
            this.levelMap = [
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,1,1,1,0,0,0],[0,0,0,0,1,5,1,0,0,0],[0,1,1,1,1,0,1,0,0,0],[0,1,5,4,0,4,1,1,1,0],[0,1,1,1,2,4,0,5,1,0],[0,0,0,1,4,1,1,1,1,0],[0,0,0,1,5,1,0,0,0,0],[0,0,0,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,0,0,0,0],[0,1,2,0,0,1,0,0,0,0],[0,1,0,4,4,1,0,1,1,1],[0,1,0,4,0,1,0,1,5,1],[0,1,1,1,0,1,1,1,5,1],[0,0,1,1,0,0,0,0,5,1],[0,0,1,0,0,0,1,0,0,1],[0,0,1,0,0,0,1,1,1,1],[0,0,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,0,0],[0,1,0,0,0,0,0,1,1,1],[1,1,4,1,1,1,0,0,0,1],[1,0,2,0,4,0,0,4,0,1],[1,0,5,5,1,0,4,0,1,1],[1,1,5,5,1,0,0,0,1,0],[0,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,0,0,0,0],[0,1,1,0,0,1,0,0,0,0],[0,1,2,4,0,1,0,0,0,0],[0,1,1,4,0,1,1,0,0,0],[0,1,1,0,4,0,1,0,0,0],[0,1,5,4,0,0,1,0,0,0],[0,1,5,5,6,5,1,0,0,0],[0,1,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,1,0,0,0],[0,0,1,2,0,1,1,1,0,0],[0,0,1,0,4,0,0,1,0,0],[0,1,1,1,0,1,0,1,1,0],[0,1,5,1,0,1,0,0,1,0],[0,1,5,4,0,0,1,0,1,0],[0,1,5,0,0,0,4,0,1,0],[0,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,1,1,1,1,1,1,1],[0,0,1,1,0,0,1,0,2,1],[0,0,1,0,0,0,1,0,0,1],[0,0,1,4,0,4,0,4,0,1],[0,0,1,0,4,1,1,0,0,1],[1,1,1,0,4,0,1,0,1,1],[1,5,5,5,5,5,0,0,1,0],[1,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,1,1,1,1,1,1,0],[0,1,1,1,0,0,0,0,1,0],[1,1,5,0,4,1,1,0,1,1],[1,5,5,4,0,4,0,0,2,1],[1,5,5,0,4,0,4,0,1,1],[1,1,1,1,1,1,0,0,1,0],[0,0,0,0,0,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[1,1,1,1,1,1,1,0,0,0],[1,0,0,2,0,0,1,1,0,0],[1,0,4,0,4,0,0,1,0,0],[1,0,0,4,0,4,0,1,0,0],[1,1,1,4,1,1,1,1,0,0],[1,0,5,0,5,5,1,0,0,0],[1,0,0,0,0,0,1,0,0,0],[1,0,0,1,0,5,1,0,0,0],[1,0,0,5,0,0,1,0,0,0],[1,1,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,1,0],[0,1,5,0,0,0,5,0,1,0],[0,1,0,1,0,1,0,0,1,0],[0,1,2,4,0,0,4,5,1,0],[0,1,1,1,1,1,0,4,1,0],[0,0,0,0,0,1,0,0,1,0],[0,0,0,0,0,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,0,0],[0,1,0,0,1,0,0,1,0,0],[0,1,0,4,0,0,0,1,1,0],[0,1,0,0,1,1,5,0,1,0],[0,1,1,0,4,0,5,0,1,0],[0,1,2,0,1,1,5,0,1,0],[0,1,0,4,0,0,0,1,1,0],[0,1,0,0,1,0,0,1,0,0],[0,1,1,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,1,1,0,0],[0,0,1,0,0,0,0,1,1,0],[0,1,1,5,1,1,4,0,1,0],[0,1,0,5,5,4,0,0,1,0],[0,1,0,0,1,4,0,0,1,0],[0,1,0,0,2,0,1,1,1,0],[0,1,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,0,0,0,0],[1,0,0,0,0,1,0,0,0,0],[1,0,4,4,4,1,1,0,0,0],[1,0,0,1,5,5,1,1,1,0],[1,1,0,0,5,5,4,0,1,0],[0,1,0,2,0,0,0,0,1,0],[0,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[1,1,1,1,1,1,1,0,0,0],[1,5,5,4,5,5,1,0,0,0],[1,5,5,1,5,5,1,0,0,0],[1,0,4,4,4,0,1,0,0,0],[1,0,0,4,0,0,1,0,0,0],[1,0,4,4,4,0,1,0,0,0],[1,0,0,1,2,0,1,0,0,0],[1,1,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,1,1,1,1,1,1,0],[0,0,0,1,0,0,0,0,1,0],[0,1,1,1,4,4,4,0,1,0],[0,1,2,0,4,5,5,0,1,0],[0,1,0,4,5,5,5,1,1,0],[0,1,1,1,1,0,0,1,0,0],[0,0,0,0,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,1,1,1,1,0,0,0],[0,0,0,1,5,5,1,0,0,0],[0,0,1,1,0,5,1,1,0,0],[0,0,1,0,0,4,5,1,0,0],[0,1,1,0,4,0,0,1,1,0],[0,1,0,0,1,4,4,0,1,0],[0,1,0,0,2,0,0,0,1,0],[0,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,1,1,1,1,1,0,0],[1,1,1,1,2,0,0,1,0,0],[1,0,4,0,4,4,4,1,1,0],[1,0,0,5,1,5,0,0,1,0],[1,1,0,1,1,0,1,0,1,0],[0,1,0,5,0,5,0,0,1,0],[0,1,0,0,0,1,1,1,1,0],[0,1,1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,1,1,1,1,1,0,0,0],[0,0,1,0,2,0,1,1,1,0],[0,1,1,4,1,4,0,0,1,0],[0,1,0,5,5,0,5,0,1,0],[0,1,0,0,4,4,0,1,1,0],[0,1,1,1,0,1,5,1,0,0],[0,0,0,1,0,0,0,1,0,0],[0,0,0,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,1,0],[0,1,0,0,5,1,0,2,1,0],[0,1,0,1,0,4,0,0,1,0],[0,1,0,4,5,1,4,0,1,0],[0,1,1,0,5,0,0,0,1,0],[0,0,1,0,0,1,1,1,1,0],[0,0,1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,1,1,1,1,1,0,0,0],[1,1,1,0,0,0,1,1,1,0],[1,0,5,0,4,0,5,0,1,0],[1,0,1,5,4,5,1,0,1,0],[1,0,4,0,1,0,4,0,1,0],[1,1,1,0,2,0,1,1,1,0],[0,0,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,0,0,0],[1,1,0,0,2,0,1,1,1,0],[1,0,0,4,5,4,0,0,1,0],[1,0,4,5,4,5,4,0,1,0],[1,1,5,4,5,4,5,1,1,0],[0,1,0,5,4,1,5,0,1,0],[0,1,1,0,0,0,1,1,1,0],[0,0,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[1,1,1,1,1,1,1,0,0,0],[1,0,0,0,0,0,1,0,0,0],[1,0,4,5,4,0,1,0,0,0],[1,2,5,4,5,0,1,0,0,0],[1,0,4,5,4,0,1,0,0,0],[1,0,5,4,5,0,1,0,0,0],[1,0,0,0,0,0,1,0,0,0],[1,1,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[1,1,1,1,1,0,0,0,0,0],[1,0,0,0,1,1,1,1,1,0],[1,0,1,0,1,0,0,2,1,0],[1,0,4,0,0,0,4,0,1,0],[1,5,5,1,4,1,4,1,1,0],[1,5,0,4,0,0,0,1,0,0],[1,5,5,0,0,1,1,1,0,0],[1,1,1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,1,1,1,1,0,0,0],[0,0,0,1,0,0,1,1,1,0],[0,0,1,1,0,4,0,0,1,0],[0,0,1,0,0,0,4,0,1,0],[0,0,1,0,1,0,0,0,1,0],[0,0,1,0,1,4,1,1,1,0],[0,0,1,0,1,0,5,5,1,0],[0,0,1,0,4,2,5,5,1,0],[0,0,1,1,1,0,0,1,1,0],[0,0,0,0,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,1,0,0,0],[0,0,1,0,0,0,1,1,1,1],[0,0,1,0,0,0,1,0,0,1],[0,0,1,1,0,0,2,4,5,1],[0,1,1,1,0,1,1,1,5,1],[0,1,0,4,0,1,0,1,5,1],[0,1,0,4,0,1,0,1,1,1],[0,1,0,0,0,1,0,0,0,0],[0,1,1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,1,1,0,0],[0,1,1,0,0,4,0,1,0,0],[0,1,0,5,0,1,0,1,0,0],[0,1,0,4,5,0,0,1,0,0],[0,1,0,0,1,5,1,1,0,0],[0,1,4,0,2,0,1,0,0,0],[0,1,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,0,0,0],[1,1,0,0,0,0,1,1,0,0],[1,0,4,0,4,4,0,1,0,0],[1,5,5,5,5,5,5,1,0,0],[1,0,4,4,0,4,0,1,0,0],[1,1,1,0,2,1,1,1,0,0],[1,1,1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,1,0],[0,1,0,0,1,0,0,0,1,0],[0,1,0,4,5,5,4,0,1,0],[0,1,2,4,5,6,0,1,1,0],[0,1,0,4,5,5,4,0,1,0],[0,1,0,0,1,0,0,0,1,0],[0,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,1,1,1,1,1,0,0,0],[0,0,1,0,2,0,1,0,0,0],[0,0,1,0,4,0,1,0,0,0],[1,1,1,0,5,0,1,1,1,0],[1,0,0,0,6,0,0,0,1,0],[1,0,6,6,6,6,6,0,1,0],[1,0,0,0,6,0,0,0,1,0],[1,1,1,4,6,4,1,1,1,0],[0,0,1,0,5,0,1,0,0,0],[0,0,1,0,6,0,1,0,0,0],[0,0,1,0,5,0,1,0,0,0],[0,0,1,1,1,1,1,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,1,0,0,0],[0,1,1,0,5,2,1,1,0,0],[0,1,0,0,6,0,0,1,0,0],[0,1,0,4,6,4,0,1,0,0],[0,1,5,5,1,5,5,1,0,0],[1,1,4,0,5,0,4,1,1,0],[1,0,4,0,1,0,4,0,1,0],[1,0,0,0,1,0,0,0,1,0],[1,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,1,1,1,1,1,0,0,0],[0,1,1,0,0,0,1,1,0,0],[0,1,0,0,4,5,5,1,1,0],[1,1,4,0,1,5,4,5,1,0],[1,0,0,0,1,5,5,5,1,0],[1,0,4,1,1,1,4,0,1,0],[1,0,0,4,0,4,0,1,1,0],[1,1,2,0,0,0,0,1,0,0],[0,1,1,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,1,1,1,1,0,0,0,0,0],[0,1,0,0,1,1,1,0,0,0],[0,1,4,0,0,0,1,1,0,0],[1,1,0,0,6,0,0,1,1,0],[1,0,6,1,5,1,4,0,1,1],[1,0,0,0,5,5,0,0,2,1],[1,0,6,1,5,1,4,0,1,1],[1,1,0,0,4,0,0,1,1,0],[0,1,4,0,0,0,1,1,0,0],[0,1,0,0,1,1,1,0,0,0],[0,1,1,1,1,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,1,1,1,1,0,0,0,0,0],[0,1,0,0,1,1,1,0,0,0],[0,1,0,0,0,0,1,0,0,0],[0,1,0,4,0,0,1,0,0,0],[0,1,1,1,0,1,1,1,0,0],[0,1,0,4,0,4,0,1,0,0],[0,1,5,5,2,5,5,1,0,0],[0,1,0,0,4,0,0,1,0,0],[0,1,1,1,0,0,1,1,0,0],[0,0,0,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,0,0,0],[1,0,0,5,4,0,1,1,1,0],[1,0,5,4,5,4,0,0,1,0],[1,6,4,5,4,5,2,0,1,0],[1,0,5,4,5,4,0,1,1,0],[1,0,0,5,4,0,0,1,0,0],[1,1,1,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,0],[1,0,0,0,1,1,0,0,1,0],[1,0,1,0,4,0,4,0,1,0],[1,0,0,6,5,1,0,0,1,0],[1,1,0,1,5,2,5,1,1,0],[1,1,4,1,1,1,6,1,1,1],[1,0,0,0,0,0,0,0,0,1],[1,0,0,0,1,1,0,1,0,1],[1,1,1,1,1,1,0,0,0,1],[0,0,0,0,0,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0]]',
                '[[1,1,1,1,1,1,1,1,1,1],[1,0,0,0,1,1,0,0,0,1],[1,0,0,0,0,4,0,4,2,1],[1,1,4,1,5,1,1,4,1,1],[1,0,0,1,5,5,5,0,0,1],[1,0,0,5,5,5,1,0,0,1],[1,0,4,1,1,5,1,4,1,1],[1,1,0,1,1,0,4,0,1,0],[1,0,0,0,4,0,1,0,1,0],[1,0,0,0,1,0,0,0,1,0],[1,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,1,1,1,1,1,0],[0,1,1,1,1,0,0,0,1,0],[0,1,5,1,1,5,0,4,1,0],[1,1,4,1,0,0,4,0,1,0],[1,0,6,0,0,5,5,0,1,1],[1,0,0,0,1,6,6,4,0,1],[1,1,1,1,1,0,2,0,0,1],[0,0,0,0,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,1,1,1,1,0],[1,1,1,1,1,1,0,0,1,0],[1,0,4,0,4,2,0,0,1,0],[1,0,1,0,0,5,1,0,1,1],[1,0,0,5,0,1,5,0,0,1],[1,1,4,1,0,6,0,0,0,1],[0,1,0,0,0,1,1,1,1,1],[0,1,1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,0],[1,5,5,5,0,0,1,1,1,0],[1,0,1,1,0,0,0,0,1,0],[1,0,0,4,0,0,4,0,1,0],[1,5,1,4,1,1,4,1,1,0],[1,0,0,0,1,0,0,1,1,0],[1,1,1,0,0,2,1,1,1,0],[1,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,1,1,0,0],[0,0,1,0,0,0,0,1,1,1],[0,0,1,0,4,0,0,0,0,1],[1,1,1,0,4,0,1,1,0,1],[1,5,5,5,0,4,0,0,0,1],[1,5,5,5,4,1,4,0,1,1],[1,1,1,1,0,1,0,4,0,1],[0,0,0,1,0,0,2,0,0,1],[0,0,0,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,1,1,1,0,0],[0,0,1,0,0,0,0,1,0,0],[1,1,1,4,4,4,0,1,0,0],[1,2,0,4,5,5,0,1,0,0],[1,0,4,5,5,5,0,1,0,0],[1,1,1,1,0,0,1,1,0,0],[0,0,0,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[1,1,1,1,1,1,1,1,0,0],[1,0,0,0,0,0,0,1,0,0],[1,0,4,4,1,4,0,1,0,0],[1,0,4,5,6,0,0,1,0,0],[1,1,0,5,5,5,1,1,0,0],[0,1,1,5,4,1,1,0,0,0],[1,1,5,5,5,0,1,1,0,0],[1,0,0,6,5,4,0,1,0,0],[1,0,4,1,4,4,0,1,0,0],[1,0,0,2,0,0,0,1,0,0],[1,1,1,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0]]',
                '[[0,0,1,1,1,1,1,0,0,0],[0,0,1,0,0,0,1,1,1,0],[0,0,1,0,4,0,1,5,1,0],[0,1,1,0,4,4,5,5,1,0],[0,1,0,0,0,1,5,5,1,0],[0,1,2,1,0,4,5,5,1,0],[0,1,0,0,1,0,4,0,1,0],[0,1,1,0,4,4,1,1,1,0],[0,0,1,0,0,0,1,0,0,0],[0,0,1,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]'
            ];
            this.level = Number(storage.get('chestMapLevel')) || 0;
        }
        Map.prototype.setLevel = function (level) {
            if (level < 0)
                level = 0;
            else if (level >= this.levelMap.length)
                level = this.levelMap.length - 1;
            this.level = level;
            storage.add('chestMapLevel', level.toString());
        };
        Map.prototype.getMapData = function () {
            if (this.level + 1 > this.levelMap.length)
                return [];
            return JSON.parse(this.levelMap[this.level]);
        };
        Map.prototype.getNextLevelMapData = function () {
            this.setLevel(this.level + 1);
            return this.getMapData();
        };
        Map.prototype.getPrevLevelMapData = function () {
            this.setLevel(this.level - 1);
            return this.getMapData();
        };
        Map.prototype.getLevel = function () {
            return this.level;
        };
        Map.prototype.getTotalLevel = function () {
            return this.levelMap.length;
        };
        Map.prototype.getPeopleInitCoord = function () {
            var mapData = this.getMapData();
            for (var y = 0; y < mapData.length; y++) {
                for (var x = 0; x < mapData[y].length; x++) {
                    if (mapData[y][x] == Role.People) {
                        return {
                            Y: y,
                            X: x
                        };
                    }
                }
            }
            return {
                Y: 0,
                X: 0
            };
        };
        Map.prototype.getInitMapData = function (yLen, xLen) {
            /**
             * 获取地图坐标点的角色
             * @param y 坐标y
             * @param x 坐标x
             */
            function getMapRole(y, x) {
                return Role.Blank;
            }
            var tempMap = [];
            for (var i = 0; i < yLen; i++) {
                var tempXMap = [];
                for (var z = 0; z < xLen; z++) {
                    tempXMap.push(getMapRole(i, z));
                }
                tempMap.push(tempXMap);
            }
            return tempMap;
        };
        Map.prototype.reset = function () {
            this.setLevel(0);
        };
        return Map;
    }());
    var Game = /** @class */ (function () {
        function Game(mapData) {
            this.isOver = false;
            var gameThis = this;
            this.vueObj = new vue({
                el: '#app',
                data: {
                    Map: mapData,
                    IsDesign: false,
                    IsLook: false,
                    Level: map.getLevel() + 1,
                    Pace: 0
                },
                methods: {
                    getRoleClass: function (role) {
                        var classNames = ['mapItem'];
                        switch (role) {
                            case Role.Wall:
                                classNames.push('wall');
                                break;
                            case Role.People:
                            case Role.PeopleDot:
                                classNames.push('people');
                                break;
                            case Role.Chest:
                            case Role.ChestDot:
                                classNames.push('chest');
                                break;
                            case Role.Dot:
                                classNames.push('dot');
                                break;
                        }
                        return classNames.join(' ');
                    },
                    SetRole: function (y, x) {
                        if (this.IsDesign) {
                            var role = this.Map[y][x];
                            var newRole = role + 1;
                            if (newRole == Role.PeopleDot)
                                newRole++;
                            if (newRole > Role.ChestDot) {
                                newRole = Role.Blank;
                            }
                            this.$set(this.Map[y], x, newRole);
                            console.info(JSON.stringify(this.Map));
                        }
                    },
                    Up: function () {
                        if (this.IsLook)
                            gameThis.prevLevel();
                        else if (!this.isOver) {
                            people.move(MovePotion.Up);
                        }
                    },
                    Down: function () {
                        if (this.IsLook)
                            gameThis.nextLevel();
                        else if (!this.isOver)
                            people.move(MovePotion.Down);
                    },
                    Left: function () {
                        if (this.IsLook)
                            gameThis.prevLevel();
                        else if (!this.isOver)
                            people.move(MovePotion.Left);
                    },
                    Right: function () {
                        if (this.IsLook)
                            gameThis.nextLevel();
                        else if (!this.isOver)
                            people.move(MovePotion.Right);
                    },
                    Reload: function () {
                        this.Pace = 0;
                        this.Map = map.getMapData();
                        people.setCoord(map.getPeopleInitCoord());
                    },
                    Reset: function () {
                        map.reset();
                        this.Reload();
                        this.Pace = 0;
                        this.Level = map.getLevel() + 1;
                        gameThis.showLevelName();
                    },
                    Empty: function () {
                        this.IsDesign = true;
                        this.Map = map.getInitMapData(12, 10);
                    },
                    Look: function () {
                        if (!this.IsLook) {
                            msg.msg('按方向键选择关卡');
                            this.IsLook = true;
                        }
                        else {
                            msg.msg('取消选择关卡');
                            this.IsLook = false;
                        }
                    }
                },
                mounted: function () {
                    gameThis.showLevelName();
                }
            });
        }
        Game.prototype.getCoordRole = function (coord) {
            return this.vueObj.Map[coord.Y][coord.X];
        };
        Game.prototype.setCoordRole = function (coord, role) {
            this.vueObj.$set(this.vueObj.Map[coord.Y], coord.X, role);
        };
        Game.prototype.verifySuccess = function () {
            var _this = this;
            var isPass = true;
            for (var y = 0; y < this.vueObj.Map.length; y++) {
                for (var x = 0; x < this.vueObj.Map[y].length; x++) {
                    var role = this.vueObj.Map[y][x];
                    if (role == Role.Dot || role == Role.PeopleDot) {
                        isPass = false;
                        break;
                    }
                }
            }
            if (isPass) {
                if (map.getLevel() + 1 == map.getTotalLevel()) {
                    this.isOver = true;
                    msg.msg('恭喜通关！撒花撒花！');
                }
                else {
                    msg.msg('恭喜通过第' + (map.getLevel() + 1) + '关，共计用了' + this.vueObj.Pace + '步，即将进入下一关');
                    setTimeout(function () {
                        _this.nextLevel();
                    }, 2000);
                }
            }
        };
        Game.prototype.nextLevel = function () {
            this.initLevelData(map.getNextLevelMapData());
        };
        Game.prototype.prevLevel = function () {
            this.initLevelData(map.getPrevLevelMapData());
        };
        Game.prototype.initLevelData = function (mapData) {
            this.vueObj.Level = map.getLevel() + 1;
            this.vueObj.Map = mapData;
            people.setCoord(map.getPeopleInitCoord());
            this.showLevelName();
            this.resetPace();
        };
        Game.prototype.showLevelName = function () {
            msg.msg('进入第' + (map.getLevel() + 1) + '关');
        };
        Game.prototype.addPace = function () {
            this.vueObj.Pace++;
        };
        Game.prototype.resetPace = function () {
            this.vueObj.Pace = 0;
        };
        return Game;
    }());
    var map = new Map();
    var people = new People(map.getPeopleInitCoord());
    var game = new Game(map.getMapData());
    window.addEventListener('keyup', function (e) {
        switch (e.keyCode) {
            case 38:
                people.move(MovePotion.Up);
                break;
            case 40:
                people.move(MovePotion.Down);
                break;
            case 37:
                people.move(MovePotion.Left);
                break;
            case 39:
                people.move(MovePotion.Right);
                break;
        }
    });
});
